package com.atguigu.tingshu.album.api;

import com.alibaba.fastjson.JSONObject;
import com.atguigu.tingshu.album.mapper.BaseCategoryViewMapper;
import com.atguigu.tingshu.album.service.BaseCategoryService;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.model.album.BaseAttribute;
import com.atguigu.tingshu.model.album.BaseCategory1;
import com.atguigu.tingshu.model.album.BaseCategory3;
import com.atguigu.tingshu.model.album.BaseCategoryView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@Tag(name = "分类管理")
@RestController
@RequestMapping(value="/api/album/category")
@SuppressWarnings({"all"})
public class BaseCategoryApiController {
	
	@Autowired
	private BaseCategoryService baseCategoryService;


//	分类数据查询
	@Operation(summary = "分类查询")
	@GetMapping("getBaseCategoryList")
	public Result getBaseCategoryList(){
		List<JSONObject> list = baseCategoryService.getBaseCategoryList();
		return Result.ok(list);
	}
//	http://127.0.0.1/api/album/category/findAttribute/3
//	标签数据查询
	@Operation(summary = "根据一级分类Id获取专辑标签中的属性与属性值")
	@GetMapping("/findAttribute/{category1Id}")
	public Result findAttribute(@Parameter( name = "category1Id",description = "一级分类Id") @PathVariable Long category1Id){
//		调用service层方法
		List<BaseAttribute> list = baseCategoryService.findAttribute(category1Id);
		return Result.ok(list);
	}
	@Operation(summary = "根据三级分类id获取对应的信息")
	@GetMapping("/getCategoryInfo/{category3Id}")
	public Result getCategoryInfo(@PathVariable Long category3Id){
		BaseCategoryView categoryInfo = baseCategoryService.getCategoryInfo(category3Id);
		return Result.ok(categoryInfo);
	}

//	http://127.0.0.1/api/album/category/getBaseCategoryList/1
	@Operation(summary = "根据分类id获取分类信息")
	@GetMapping("/getBaseCategoryList/{categoryId}")
	public Result getBaseCategoryList(@PathVariable Long categoryId){
		JSONObject jsonObject = baseCategoryService.getBaseCategoryList(categoryId);
		return Result.ok(jsonObject);
	}


//	http://127.0.0.1/api/album/category/findTopBaseCategory3/1
	@Operation(summary = "根据一个分类id查询对应的三级分类")
	@GetMapping("/findTopBaseCategory3/{category1Id}")
	public Result<List<BaseCategory3>> findTopBaseCategory3(@PathVariable Long category1Id){
		List<BaseCategory3> list =  baseCategoryService.findTopBaseCategory3(category1Id);
		return Result.ok(list);
	}
//查询所有一级分类数据
	@Operation(summary = "查询所有一级分类数据")
	@GetMapping("/findAllCategory1")
	public Result<List<BaseCategory1>> findAllCategory1(){
		List<BaseCategory1> list = baseCategoryService.findAllCategory1();
		return Result.ok(list);
	}
}

